#include "scrolltext.h"


scrolltext::scrolltext(QWidget *parent)
    : QWidget{parent}
{
    textlabel = new QLabel(this);

 textlabel->setStyleSheet("QLabel {\
                          font-size: 18px;\
                          color: red;\
                          font-style: normal;\
                          font-weight: bold;}");
 textlabel->setText("This is scrolltext");
 textlabel->setFixedHeight(20);
 textlabel->hide();

 m_TopQPropertyAnimation = new QPropertyAnimation(this,"geometry");
 m_TopQPropertyAnimation->setDuration(600);


}

void scrolltext::AnimationStart()
{
    static int current_end_animation = 0;

    if(textlabel->isHidden())
        textlabel->show();
    m_TopQPropertyAnimation->setStartValue(QRect(0,textlabel->height(),textlabel->width(),textlabel->height()));
    m_TopQPropertyAnimation->setEndValue(QRect(0,0,textlabel->width(),textlabel->height()));
    m_TopQPropertyAnimation->setEasingCurve(QEasingCurve::OutQuart);
    m_TopQPropertyAnimation->start(QAbstractAnimation::KeepWhenStopped);

    current_end_animation++;

    QTimer *timer = new QTimer(this);
    timer->start(3000);


    connect(timer,&QTimer::timeout,this,[=]{
        if(current_end_animation == 1){
            m_TopQPropertyAnimation->setStartValue(QRect(0,0, textlabel->width(),textlabel->height()));
            m_TopQPropertyAnimation->setEndValue(QRect(0,textlabel->height() + 10 , textlabel->width(),textlabel->height()));
            m_TopQPropertyAnimation->start();

            timer->stop();
            delete timer;
            current_end_animation--;
        }else{
            current_end_animation--;
        }
    });


}
